using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

using FreeFlow.Client;

namespace FreeFlow.WinFormsControls
{
	/// <summary>
	/// An image control.
	/// </summary>
	public class ImageControl : PictureBox, IFillable
	{
    /// <summary>
    /// Creates a new <see cref="ImageControl"/> instance.
    /// </summary>
		public ImageControl()
		{
    }
    #region IFillable Members

    /// <summary>
    /// Renders the image with static layout information using the specified field.
    /// </summary>
    /// <param name="field">Field.</param>
    public void Render(FreeFlow.Client.Field field)
    {
      ImageField imageField = (ImageField)field;
      if (imageField.Image != null)
      {
        MemoryStream stream = new MemoryStream(imageField.Image);
        Bitmap bitmap = new Bitmap(stream);
        Image = bitmap;
      }
    }

    /// <summary>
    /// Fills the image with values from the specified field.
    /// </summary>
    /// <param name="field">Field.</param>
    public void Fill(FreeFlow.Client.Field field)
    {
    }

    /// <summary>
    /// Fills the field from the control.
    /// </summary>
    /// <param name="field">Field.</param>
    public void FillField(Field field)
    {
    }

    #endregion
  }
}
